package com.darchrow.demo.controller;

/**
 * @author mdl
 * @date 2020/4/27 15:57
 */

import com.darchrow.demo.rocketmqtest.JmsConfig;
import com.darchrow.demo.rocketmqtest.Producer;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.client.producer.SendResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@Slf4j
@RestController
@RequestMapping(value = "order")
public class OrderController {

    @Autowired
    private Producer producer;

    private List<String> mesList;

    /**
     * 初始化消息
     */
    public OrderController() {
        mesList = new ArrayList<>();
        mesList.add("小小");
        mesList.add("爸爸");
        mesList.add("妈妈");
        mesList.add("爷爷");
        mesList.add("奶奶");

    }

    @RequestMapping("/text/rocketmq")
    public Object callback() throws Exception {
        //总共发送五次消息
        for (String s : mesList) {
            //发送
            SendResult sendResult = producer.send(JmsConfig.TOPIC, "testtag", ("小小一家人的称谓:" + s));
            log.info("输出生产者信息={}",sendResult);
        }
        return "成功";
    }
}
